package com.jcfk.system.controller;

import cn.hutool.core.util.StrUtil;
import com.jcfk.common.business.enums.AvailableStatus;
import com.jcfk.common.business.log.annotation.RequestLogHeader;
import com.jcfk.common.business.utils.DataBindHelper;
import com.jcfk.common.web.domain.DataPage;
import com.jcfk.common.web.domain.ReqPageParam;
import com.jcfk.common.web.domain.RetPage;
import com.jcfk.common.web.domain.RetResult;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;

import com.jcfk.system.domain.query.SysNoticeReadRecordQuery;
import com.jcfk.system.domain.dto.SysNoticeReadRecordDTO;
import com.jcfk.system.service.SysNoticeReadRecordService;
import com.jcfk.common.core.utils.ExcelUtils;

import java.util.List;

/**
 * 通知阅读记录
 *
 * @author yrl
 * @email 
 * @date 2024-12-06
 */
@Api(tags = {"通知阅读记录管理"})
@RestController
@RequestMapping("sysnoticereadrecord")
public class SysNoticeReadRecordController {
    @Autowired
    private SysNoticeReadRecordService sysNoticeReadRecordService;

    /**
     * 分页列表
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "ReqPageParam<SysNoticeReadRecordQuery>", name = "requestParam", value = "", required = true)
    })
    @ApiOperation("分页查询通知阅读记录")
    @PostMapping("/queryByPage")
    public RetPage<SysNoticeReadRecordDTO> queryByPage(@RequestBody ReqPageParam<SysNoticeReadRecordQuery> requestParam) {
        DataPage<SysNoticeReadRecordDTO> page = new DataPage<SysNoticeReadRecordDTO>((long) requestParam.getCurrent(),
                (long) requestParam.getSize(),
                requestParam.getSort().getOrderItem(),
            SysNoticeReadRecordDTO.class);
        page = sysNoticeReadRecordService.queryByPage(page, requestParam.getData());

        return new RetPage<>(page);
    }


    /**
     *  通知阅读记录
     * 根据id 查询详情
     */
    @ApiOperation("查询通知阅读记录")
    @GetMapping("/get/{id}")
    public RetResult<SysNoticeReadRecordDTO> get(@PathVariable("id") String id) {
            SysNoticeReadRecordDTO item = sysNoticeReadRecordService.get(id);
        return RetResult.ok(item);
    }

    /**
     * 添加/更新管理通知阅读记录
     */
    @ApiOperation("保存通知阅读记录")
    @PostMapping("/save")
    @RequestLogHeader(modular = "通知阅读记录管理", businessType = "保存")
    public RetResult<?> save(@RequestBody @Valid SysNoticeReadRecordDTO sysNoticeReadRecord) {
        // 数据校验
        RetResult ret = sysNoticeReadRecordService.isValid(sysNoticeReadRecord);
        if (!ret.getCode().equals(RetResult.SUCCESS)) {
            return ret;
        }

        if (StrUtil.isEmpty(sysNoticeReadRecord.getId())){
            // 新增
            sysNoticeReadRecordService.insert(sysNoticeReadRecord);
        } else{
            // 更新
            sysNoticeReadRecordService.update(sysNoticeReadRecord);
        }
        return RetResult.ok();

    }

    /**
     *  批量删除通知阅读记录
     */
    @ApiOperation("批量删除通知阅读记录")
    @PostMapping("/delete")
    @RequestLogHeader(modular = "通知阅读记录管理", businessType = "批量删除")
    public RetResult<?> delete(@RequestBody SysNoticeReadRecordDTO sysNoticeReadRecord) {
        return RetResult.ok(sysNoticeReadRecordService.removeBigBatch(sysNoticeReadRecord.getIds()));
    }





    /**
     *  删除通知阅读记录
     */
    @ApiOperation("删除通知阅读记录")
    @PostMapping("/deleteItem/{id}")
    @RequestLogHeader(modular = "通知阅读记录管理", businessType = "删除")
    public RetResult<?> deleteItem(@PathVariable("id") String id) {
        sysNoticeReadRecordService.deleteItem(id);
        return RetResult.ok();
    }


    /**
     * list列表
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "ReqPageParam<SysNoticeReadRecordQuery>", name = "requestParam", value = "", required = true)
    })
    @ApiOperation("查询通知阅读记录")
    @PostMapping("/getList")
    public RetResult<List<SysNoticeReadRecordDTO>> getList(@RequestBody SysNoticeReadRecordQuery requestParam) {

        return RetResult.ok(sysNoticeReadRecordService.getList(requestParam));
    }
}
